﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for TAApplicantSearchDB
/// </summary>
/// 
namespace CE.TravelInsurance
{
    public class TAApplicantSearchDB
    {
        public TAApplicantSearchDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(TAApplicantSearch taapplicantsearch)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocTAApplicantSearchInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();
            #region Parameter
            _sPara.Add("@TAAppSeaId", taapplicantsearch.TAAppSeaId);
            _sPara.Add("@Name", taapplicantsearch.Name);
            _sPara.Add("@EmailAddress", taapplicantsearch.EmailAddress);
            _sPara.Add("@MobileNum", taapplicantsearch.MobileNum);
            _sPara.Add("@PlanType", taapplicantsearch.PlanType);
            _sPara.Add("@TripType", taapplicantsearch.TripType);
            _sPara.Add("@CountryID", taapplicantsearch.CountryID);
            _sPara.Add("@AreaID", taapplicantsearch.AreaID);
            _sPara.Add("@CoverageLevel", taapplicantsearch.CoverageLevel);
            _sPara.Add("@Duration", taapplicantsearch.Duration);
            _sPara.Add("@StartDate", taapplicantsearch.StartDate);
            _sPara.Add("@EndDate", taapplicantsearch.EndDate);
            _sPara.Add("@ChildAge", taapplicantsearch.ChildAge);
            _sPara.Add("@AdultAge", taapplicantsearch.AdultAge);
            _sPara.Add("@NoOfTravellers", taapplicantsearch.NoOfTravellers);
            _sPara.Add("@TotalPremium", taapplicantsearch.TotalPremium);
            _sPara.Add("@NoofAdults", taapplicantsearch.NoofAdults);
            _sPara.Add("@DOBAdult1", taapplicantsearch.DOBAdult1);
            _sPara.Add("@DOBAdult2", taapplicantsearch.DOBAdult2);
            _sPara.Add("@DOBAdult3", taapplicantsearch.DOBAdult3);
            _sPara.Add("@DOBAdult4", taapplicantsearch.DOBAdult4);
            _sPara.Add("@NoofChilds", taapplicantsearch.NoofChilds);
            _sPara.Add("@DOBChild1", taapplicantsearch.DOBChild1);
            _sPara.Add("@DOBChild2", taapplicantsearch.DOBChild2);
            _sPara.Add("@DOBChild3", taapplicantsearch.DOBChild3);
            _sPara.Add("@DOBChild4", taapplicantsearch.DOBChild4);
            _sPara.Add("@DOBChild5", taapplicantsearch.DOBChild5);
            _sPara.Add("@DOBChild6", taapplicantsearch.DOBChild6);
            _sPara.Add("@RefCEUserId", taapplicantsearch.RefCEUserId);
            _sPara.Add("@ViewedDetailId", taapplicantsearch.ViewedDetailId);
            _sPara.Add("@info1", taapplicantsearch.Info1);
            //_sPara.Add("@info2", taapplicantsearch.Info2);
            //_sPara.Add("@info3", taapplicantsearch.Info3);
            //_sPara.Add("@info4", taapplicantsearch.Info4);
            //_sPara.Add("@info5", taapplicantsearch.Info5);
            //_sPara.Add("@info6", taapplicantsearch.Info6);
            //_sPara.Add("@info7", taapplicantsearch.Info7);
            //_sPara.Add("@info8", taapplicantsearch.Info8);
            //_sPara.Add("@info9", taapplicantsearch.Info9);
            //_sPara.Add("@info10", taapplicantsearch.Info10);
            //_sPara.Add("@info11", taapplicantsearch.Info11);
            //_sPara.Add("@info12", taapplicantsearch.Info12);
            _sPara.Add("@Ninfo1", taapplicantsearch.Ninfo1);
            _sPara.Add("@Ninfo2", taapplicantsearch.Ninfo2);
            _sPara.Add("@Ninfo3", taapplicantsearch.Ninfo3);

            #endregion
            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 UpdatePremium(Int64 TAAppSeaId, float TotalPremium, Int64 Ninfo1, Int64 Ninfo2, string Info2)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocTAApplicantSearchUpdatePremiumPlan";

            SortedList _sPara = new SortedList();
            _sPara.Add("@TAAppSeaId", TAAppSeaId);
            _sPara.Add("@TotalPremium", TotalPremium);
            _sPara.Add("@Ninfo1", Ninfo1);
            _sPara.Add("@Ninfo2", Ninfo2);
            _sPara.Add("@Info2", Info2);
            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }


        public Int64 UpdatePremium(Int64 TAAppSeaId, float TotalPremium, Int64 Ninfo1, Int64 Ninfo2)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocTAApplicantSearchUpdatePremium";

            SortedList _sPara = new SortedList();
            _sPara.Add("@TAAppSeaId", TAAppSeaId);
            _sPara.Add("@TotalPremium", TotalPremium);
            _sPara.Add("@Ninfo1", Ninfo1);
            _sPara.Add("@Ninfo2", Ninfo2);
            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 UpdateProfileDetails(Int64 TAAppSeaId, string Name, string Mobile, string EmailAddress)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocTAApplicantSearchUpdateProfileDetails";

            SortedList _sPara = new SortedList();
            _sPara.Add("@TAAppSeaId", TAAppSeaId);
            _sPara.Add("@Name", Name);
            _sPara.Add("@MobileNum", Mobile);
            _sPara.Add("@EmailAddress", EmailAddress);
            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 UpdateStatus(Int64 TAAppSeaId, string info1)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocTAApplicantSearchUpdateStatusSingleItem]";

            SortedList _sPara = new SortedList();
            _sPara.Add("@TAAppSeaId", TAAppSeaId);
            _sPara.Add("@info1", info1);
            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 UpdateFromSearchPage(Int64 TAAppSeaId, Int64 Ninfo3)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocTAApplicantSearchUpdateACESingleItem";

            SortedList _sPara = new SortedList();
            _sPara.Add("@TAAppSeaId", TAAppSeaId);
            _sPara.Add("@Ninfo3", Ninfo3);
            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public TAApplicantSearch GetTAApplicantSearchItem(Int64 TAAppSeaId)
        {
            TAApplicantSearch _taapplicantsearch = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocTAApplicantSearchSelectSingleItem";

            SortedList _sPara = new SortedList();
            _sPara.Add("@TAAppSeaId", TAAppSeaId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _sPara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _taapplicantsearch = new TAApplicantSearch();
                    _taapplicantsearch = FillDataRecord(_dt, 0);
                }
            }
            return _taapplicantsearch;
        }

        private TAApplicantSearch FillDataRecord(DataTable myDataTable, int rowId)
        {
            TAApplicantSearch myTAApplicantSearch = new TAApplicantSearch();
            myTAApplicantSearch.TAAppSeaId = Convert.ToInt64(myDataTable.Rows[rowId]["TAAppSeaId"].ToString());
            myTAApplicantSearch.Name = myDataTable.Rows[rowId]["Name"].ToString();
            myTAApplicantSearch.EmailAddress = myDataTable.Rows[rowId]["EmailAddress"].ToString();
            myTAApplicantSearch.MobileNum = myDataTable.Rows[rowId]["MobileNum"].ToString();
            myTAApplicantSearch.PlanType = myDataTable.Rows[rowId]["PlanType"].ToString();
            myTAApplicantSearch.TripType = myDataTable.Rows[rowId]["TripType"].ToString();
            myTAApplicantSearch.CountryID = Convert.ToInt64(myDataTable.Rows[rowId]["CountryID"].ToString());
            myTAApplicantSearch.AreaID = Convert.ToInt64(myDataTable.Rows[rowId]["AreaID"].ToString());
            myTAApplicantSearch.CoverageLevel = myDataTable.Rows[rowId]["CoverageLevel"].ToString();
            myTAApplicantSearch.Duration = Convert.ToInt32(myDataTable.Rows[rowId]["Duration"].ToString());
            myTAApplicantSearch.StartDate = DateTime.Parse(myDataTable.Rows[rowId]["StartDate"].ToString());
            myTAApplicantSearch.EndDate = DateTime.Parse(myDataTable.Rows[rowId]["EndDate"].ToString());
            myTAApplicantSearch.ChildAge = Convert.ToInt32(myDataTable.Rows[rowId]["ChildAge"].ToString());
            myTAApplicantSearch.AdultAge = Convert.ToInt32(myDataTable.Rows[rowId]["AdultAge"].ToString());
            myTAApplicantSearch.NoOfTravellers = Convert.ToInt32(myDataTable.Rows[rowId]["NoOfTravellers"].ToString());
            myTAApplicantSearch.TotalPremium = float.Parse(myDataTable.Rows[rowId]["TotalPremium"].ToString());
            myTAApplicantSearch.NoofAdults = Convert.ToInt32(myDataTable.Rows[rowId]["NoofAdults"].ToString());
            myTAApplicantSearch.DOBAdult1 = DateTime.Parse(myDataTable.Rows[rowId]["DOBAdult1"].ToString());
            myTAApplicantSearch.DOBAdult2 = DateTime.Parse(myDataTable.Rows[rowId]["DOBAdult2"].ToString());
            myTAApplicantSearch.DOBAdult3 = DateTime.Parse(myDataTable.Rows[rowId]["DOBAdult3"].ToString());
            myTAApplicantSearch.DOBAdult4 = DateTime.Parse(myDataTable.Rows[rowId]["DOBAdult4"].ToString());
            myTAApplicantSearch.NoofChilds = Convert.ToInt32(myDataTable.Rows[rowId]["NoofChilds"].ToString());
            myTAApplicantSearch.DOBChild1 = DateTime.Parse(myDataTable.Rows[rowId]["DOBChild1"].ToString());
            myTAApplicantSearch.DOBChild2 = DateTime.Parse(myDataTable.Rows[rowId]["DOBChild2"].ToString());
            myTAApplicantSearch.DOBChild3 = DateTime.Parse(myDataTable.Rows[rowId]["DOBChild3"].ToString());
            myTAApplicantSearch.DOBChild4 = DateTime.Parse(myDataTable.Rows[rowId]["DOBChild4"].ToString());
            myTAApplicantSearch.DOBChild5 = DateTime.Parse(myDataTable.Rows[rowId]["DOBChild5"].ToString());
            myTAApplicantSearch.DOBChild6 = DateTime.Parse(myDataTable.Rows[rowId]["DOBChild6"].ToString());
            myTAApplicantSearch.RefCEUserId = Convert.ToInt32(myDataTable.Rows[rowId]["RefCEUserId"].ToString());
            myTAApplicantSearch.ViewedDetailId = Convert.ToInt32(myDataTable.Rows[rowId]["ViewedDetailId"].ToString());

            if (myDataTable.Rows[rowId]["info1"] != null && myDataTable.Rows[rowId]["info1"] != "")
                myTAApplicantSearch.Info1 = myDataTable.Rows[rowId]["info1"].ToString();
            else
                myTAApplicantSearch.Info1 = "";

            if (myDataTable.Rows[rowId]["info2"] != null && myDataTable.Rows[rowId]["info2"] != "")
                myTAApplicantSearch.Info2 = myDataTable.Rows[rowId]["info2"].ToString();
            else
                myTAApplicantSearch.Info2 = "";

            //myTAApplicantSearch.Info3 = myDataTable.Rows[rowId]["info3"].ToString();
            //myTAApplicantSearch.Info4 = myDataTable.Rows[rowId]["info4"].ToString();
            //myTAApplicantSearch.Info5 = myDataTable.Rows[rowId]["info5"].ToString();
            //myTAApplicantSearch.Info6 = myDataTable.Rows[rowId]["info6"].ToString();
            //myTAApplicantSearch.Info7 = myDataTable.Rows[rowId]["info7"].ToString();
            //myTAApplicantSearch.Info8 = myDataTable.Rows[rowId]["info8"].ToString();
            //myTAApplicantSearch.Info9 = myDataTable.Rows[rowId]["info9"].ToString();
            //myTAApplicantSearch.Info10 = myDataTable.Rows[rowId]["info10"].ToString();
            //myTAApplicantSearch.Info11 = myDataTable.Rows[rowId]["info11"].ToString();
            //myTAApplicantSearch.Info12 = myDataTable.Rows[rowId]["info12"].ToString();

            if (myDataTable.Rows[rowId]["Ninfo1"] != null && myDataTable.Rows[rowId]["Ninfo1"] != "")
                myTAApplicantSearch.Ninfo1 = Convert.ToInt64(myDataTable.Rows[rowId]["Ninfo1"].ToString());
            else
                myTAApplicantSearch.Ninfo1 = 0;

            if (myDataTable.Rows[rowId]["Ninfo2"] != null && myDataTable.Rows[rowId]["Ninfo2"] != "")
                myTAApplicantSearch.Ninfo2 = Convert.ToInt64(myDataTable.Rows[rowId]["Ninfo2"].ToString());
            else
                myTAApplicantSearch.Ninfo2 = 0;

            if (myDataTable.Rows[rowId]["Ninfo3"] != null && myDataTable.Rows[rowId]["Ninfo3"] != "")
                myTAApplicantSearch.Ninfo3 = Convert.ToInt64(myDataTable.Rows[rowId]["Ninfo3"].ToString());
            else
                myTAApplicantSearch.Ninfo3 = 0;

            return myTAApplicantSearch;
        }
    }
}